/*
 ============================================================================
 Name        : tokens.c
 Author      : cihan
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned int get_tokens(int *num_tokens, char* tokens[]) {

	  char str[1024];
      char  * cmd_object[5] = {0} ;
      unsigned int k,cmd;

     cmd =0;

      *num_tokens = 0;



	  gets(str); //dangerous function, no internal check,
	           //could write over other variables in memory
	           //instead fgets()?

	 // fgets(str, sizeof str, stdin);

	//	  fgets(str, sizeof str, stdin);
       //if (!strcmp( str, "|" ))



     /* for (counter= 0 ; counter < 5 ; counter ++) {
          cmd_object[counter]=(char *)malloc((strlen(str)+1)*sizeof(char));
      }*/


	  tokens[0] = (char *)strtok (str," \t\n");


	  while(tokens[*num_tokens] != NULL)
	  {
		*num_tokens = *num_tokens + 1;
	    tokens[*num_tokens] = (char *)strtok (NULL, "  \t\r\n");
	  }


    	for(k=0; k < *num_tokens; k++) {

            if(!strcmp(tokens[k],"|")) {
            	cmd = 69 ;
            	break;
            }

            if(!strcmp(tokens[k],"&")) {
                   cmd = 31 ;
                   break;
            }

        }



	  return cmd;
}
